pragma Singleton
import QtQuick 2.7
import plugins.FileIo 1.0



Item{
    id:root
    property alias weather:weather

    QtObject{
        id:weather
        //property string apiUrl: "http://api.avatardata.cn/Weather/Query?key=fa536bb1b6f344f7a917492aef51668f&cityname=上海"
        property string apiUrl: "http://api.avatardata.cn"
        property string key: "fa536bb1b6f344f7a917492aef51668f"
        property string city: "上海"
        property string postUrl: apiUrl + "/Weather/Query?key=" + key + "&cityname=" + city
        property string result
    }



    function getWeatherData() {
        var xhr = new XMLHttpRequest;
        xhr.open("GET", weather.postUrl);
        xhr.onreadystatechange = function() {
            if (xhr.readyState === XMLHttpRequest.DONE){
                weather.result = xhr.responseText
            }
        }
        xhr.send();
    }

    Component.onCompleted: {
        getWeatherData()
    }
}
